﻿using DomenModel;
using Infrastructure.Repositories;
using Infrastructure.Service;
using Model.Repositories;
using Model.Repositories.Interfaces;
using Model.Service;
using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OMS.Infrastructure
{
    public class NinjectDependencyResolverForController : IDependencyResolver
    {
        private IKernel kernel;
        public NinjectDependencyResolverForController()
        {
            kernel = new StandardKernel();
            AddBindings();
        }
        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }
        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }
        private void AddBindings()
        {
            kernel.Bind<ICrud<CreditCard>>().To<CreditCardRepo>();
            //kernel.Bind<ICrud<Dimension>>().To<DimensionRealization>();
            kernel.Bind<IItemCrud>().To<ItemRepo>();
            kernel.Bind<ICrudItemDimension>().To<ItemDimensionRepo>();
            kernel.Bind<ICrud<Order>>().To<OrderRepo>();
            kernel.Bind<IOrderDetailsCrud>().To<OrderDetailsRepo>();
            kernel.Bind<ICrud<Role>>().To<RoleRepo>();
            kernel.Bind<ICrud<Status>>().To<StatusRepo>();
            kernel.Bind<IUserCrud>().To<UserRepo>();

            kernel.Bind<IAdministratorService>().To<AdministratorService>();
            kernel.Bind<IItemService>().To<ItemService>();
            kernel.Bind<IOrderingService>().To<OrderingService>();

            kernel.Bind<ICustomRoleProvider>().To<CustomRoleProvider>().InSingletonScope();
            kernel.Bind<IAuthorizationProvider>().To<AuthorizationProvider>().InSingletonScope();
                //.WithPropertyValue("_dbUsers", new UserRealization());
                //.WithConstructorArgument("_dbUsers", new UserRealization());
                //.WhenInjectedInto<AuthorizationProvider>();


        }
    }
}